package com.kingdee.hackson.controller;

import com.kingdee.hackson.dto.lc.Response;
import com.kingdee.hackson.entity.Position;
import com.kingdee.hackson.service.ILCService;
import com.kingdee.hackson.service.impl.InitOrgIdServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/lc")
public class LCController {
    private static final Logger LOGGER = LoggerFactory.getLogger(LCController.class);
    @Resource
    private CacheManager cacheManager;
    @Autowired
    private ILCService ilcService;
    @GetMapping("/queryone")
    public Response queryone(){
        long start1 = System.currentTimeMillis();
        try {
            return ilcService.query();
        }catch (Exception e){
            LOGGER.error("",e);
            throw e;
        }finally {
            LOGGER.info("queryone总耗时：" + (System.currentTimeMillis() - start1));
        }
    }
    // http://localhost:8080/lc/cacheTest
    @GetMapping("/cacheTest")
    public void cacheTest() {
        // 显示所有的Cache空间
        System.out.println(StringUtils.join(cacheManager.getCacheNames(), ","));
        Cache cache = cacheManager.getCache("MyCache");
        cache.put("key", "123");
        System.out.println("缓存成功");
        String res = cache.get("key", String.class);
        System.out.println(res);

    }
}
